<template>
    <div>
        <el-select filterable @select='handleSelectionChange' placeholder='请选择输入文件' v-model='fileName' class='handle-select mr10' style='width: 350px'>
            <el-option key=0 label='in0' value='in0'></el-option>
            <el-option key=1 label='in1' value='in1'></el-option>
            <el-option key=2 label='in2' value='in2'></el-option>
            <el-option key=3 label='in3' value='in3'></el-option>
            <el-option key=4 label='in4' value='in4'></el-option>
            <el-option key=5 label='in5' value='in5'></el-option>
            <el-option key=6 label='in6' value='in6'></el-option>
            <el-option key=7 label='in7' value='in7'></el-option>
            <el-option key=8 label='in8' value='in8'></el-option>
            <el-option key=9 label='in9' value='in9'></el-option>
            <el-option key=10 label='out0' value='out0'></el-option>
            <el-option key=11 label='out1' value='out1'></el-option>
            <el-option key=12 label='out2' value='out2'></el-option>
            <el-option key=13 label='out3' value='out3'></el-option>
            <el-option key=14 label='out4' value='out4'></el-option>
            <el-option key=15 label='out5' value='out5'></el-option>
            <el-option key=16 label='out6' value='out6'></el-option>
            <el-option key=17 label='out7' value='out7'></el-option>
            <el-option key=18 label='out8' value='out8'></el-option>
            <el-option key=19 label='out9' value='out9'></el-option>
        </el-select>
        <div style='height: 20px'></div>
<!--        {{ codeUrl }}{{ suffix }}-->
        <el-upload
            class='upload-demo'
            drag
            :before-upload='beforeUpload()'
            :action='codeUrl'
            :limit='1'
            :on-success='handleUploadSuccess'
            :on-remove='handleUploadRemove'
        >
            <i class='el-icon-upload'></i>
            <div class='el-upload__text'>将文件拖到此处，或<em>点击上传</em></div>
            <div class='el-upload__tip' slot='tip'>只能上传不超过5MB的文件</div>
        </el-upload>
    </div>
</template>

<script>
export default {
    name: 'JudgeInUpload',
    props: ['id'],
    data() {
        return {
            upload: 0,
            fileName: '',
            codeUrl: '',
            id: -1,

        };
    },
    methods: {
        handleUploadSuccess: function(response, file, fileList) {
            // console.log(response)
            this.upload = 1;
            this.$emit('upload', this.fileName)
        },
        handleUploadRemove: function() {
            this.upload = 0;
            // this.$emit('remove', 0)
        },
        handleSelectionChange() {
            this.fileName = value
            this.id = key
        },
        beforeUpload() {
            this.codeUrl = `/api/file/uploadJudge/${this.fileName}/${this.id}`;
            console.log(this.codeUrl)
        }
    }
};
</script>

<style scoped>

</style>
